package IO3;

import java.io.*;
import java.net.URL;

/**
 * @description: IO_decoration03
 * 转换流
 * 1.字符流操作字节流
 * 2.可以指定字符集
 * InputStreamReader()
 * OutputStreamWriter()
 *
 * 数据流
 * 将数据类型保存 进行
 * DataInputStream( x )  //含参数 一个标准IO流
 * DataOutputStream( x )
 *
 * 对象流
 * ObjectInputStream()
 * ObjectOutputStream()
 * 打印流
 * PrintStream()
 * @date: 2019/12/17 20:02
 * @author: Vicuna
 */


public class IO_decoration03 {
    public static void main(String[] args) {
        File f = new File("src/IO3/网络流.txt");
        try (
                //嵌套一个简单的网络流
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(
                                new URL("https://www.baidu.com/").openStream(), "UTF-8"));
                BufferedWriter writer = new BufferedWriter(
                        new OutputStreamWriter(
                                new FileOutputStream(f), "UTF-8"));
        ) {
            String msg = "";
            while ((msg = reader.readLine()) != null) {
               writer.write(msg);
               writer.newLine();
            }
            writer.flush();      //  若缓冲未满 强制刷新
        } catch (IOException e) {
            System.out.println("异常");
        }
    }
}
